<template>
    <div class="login_page">
        <image src="https://diancan-1252107261.cos.accelerate.myqcloud.com/yiliao/denglu-yemian.jpg" mode="" />

        <view class="loginBtn" @click="goLoginBtn">授权登录</view>
    </div>
</template>

<script setup lang="ts">
import type { goLoginType } from '@/dataType/data'
import { goLoginApi } from '@/http/api'
//去登录
const goLoginBtn = () => {
    uni.getUserProfile({
        desc: "登录授权",
        lang: 'zh_CN',
        success: (res: any) => {

            uni.login({
                success: (res2: any) => {
                    console.log('用户信息：', res)
                    //调用登录方法
                    goLoginOk({ code: res2.code, nickName: res.userInfo.nickName, avatarUrl: res.userInfo.avatarUrl })

                },
                fail: (fail) => { },
            })
        },
    })


}


const goLoginOk = async (obj: goLoginType) => {
    const goLoginData = {
        appid: 'wxb61621e772a9f027',
        secret: '8207f36e4edaccff23ea953bfbfd94c6',
        ...obj
    }

    try {
        const res = await goLoginApi(goLoginData)
        console.log('能否token:', res)
        uni.setStorageSync('wxuser', res.data.data)

        setTimeout(() => {
            uni.navigateBack({ delta: -1 })
        }, 600)



    } catch (err) {
        console.log('处理错误：', err)
    }
}


</script>

<style lang="scss">
.login_page {
    position: relative;
    width: 100vw;
    height: 100vh;

    image {
        width: 100%;
        height: 100%;
    }

    .loginBtn {
        position: absolute;
        left: 50%;
        bottom: 20%;
        padding: 30rpx 100rpx;
        border-radius: 10rpx;
        color: #fff;
        transform: translate(-50%, -50%);
        z-index: 9999;
        background: #327aec;
    }
}
</style>